<template>
  <div>
    <el-row>
      <el-col :span="8" v-for="c in categorys" @click.native="view(c.id)" :key="c.id" >
        <el-card style="margin-bottom:20px;" shadow="hover" :body-style="{ padding: '0px' }">
            <div style="padding: 14px;">
              <h4 class="card-name" >{{c.categoryName}}</h4>
              <p class="card-description">{{c.description}}</p>
            </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>


<script>
import {getCategorys} from "@/api/category";

export default {
  name: "articleCategory",
  data(){
    return{
      categorys:[]
    }
  },
  methods:{
    view(id){
      //todo 路径传参 把文章类别传过去
      this.$router.push({path:`/category/${id}`})
    },
    getCategorys(){
      getCategorys().then((res)=>{
        if(res.data.data){
          this.categorys = res.data.data;
        }else{
          this.$message("系统错误")
        }
      }).catch((err)=>{
          this.$message("系统错误")
      })
    }
  },
  created() {
    this.getCategorys()
  }
}
</script>

<style scoped>
  .el-card{
    width: 220px;
    height: 235px;
    border-radius: 20px;
    background: url("../assets/cardBack.jpg") no-repeat;
  }
  .image{
    width: 220px;
    height: 180px;
  }
  .card-name {
    font-size: 23px;
    font-weight: 550;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: white;
    margin-top: 10px;
    margin-left: 10px;
  }
  .card-description {
    min-height: 50px;
    font-size: 14px;
    line-height: 25px;
    color: ghostwhite;
    margin-top: 10px;
    margin-left: 10px;

  }
</style>
